<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<script type="text/javascript" src="/static/jquery/jquery.form.js"></script>
	<script type="text/javascript">
        function downloadtest(id){
            window.open(id);
            window.location.reload();
        }
        function downloadtest2(id){
            window.open(id);
            window.location.reload();
        }
        function uploadanswerfile2(obj) {
            $("#eventcaseid").val(obj);
            var options={
                url:"/upload/uploadanswerfile2",
                type:"post",
                dataType:"text",
                success:function(data){
                    //答案文件的url地址保存数据库
                    $("#answerFileUrl").val(data);
                    window.location.reload();
                }
            }
            $("#inputForm22").ajaxSubmit(options);
        }


        // 上传作业文件的方法
        function uploadtaskfile2(obj) {
            $("#eventcaseid").val(obj);
            var options={
                url:"/upload/uploadtaskfile2",
                type:"post",
                dataType:"text",
                success:function(data){
                    // 作业文件的url地址保存数据库
                    $("#taskFileUrl").val(data);
                    window.location.reload();
                }
            }
            $("#inputForm22").ajaxSubmit(options);
        }


	</script>
	<title>添加作业</title>
	<meta name="decorator" content="default"/>
</head>
<body>
<ul class="nav nav-tabs">
<shiro:hasPermission name="business:course:view">
	<li><a href="${ctx}/business/course/">课程信息列表</a></li>
</shiro:hasPermission>
	<li class="active"><a href="${ctx}/business/course/addevent?id=${course.id}" >
		<shiro:hasPermission name="business:course:addtask">添加课程作业</shiro:hasPermission>
	</a></li>
</ul>
<div class="container-fluid breadcrumb">
	<div class="row-fluid span12">
		<span class="span4">课程序号: ${course.seq}</span>
		<span class="span4">课程名称: ${course.title}</span>
		<span class="span4">课程介绍: ${course.introduction}</span>
	</div>
	<div class="row-fluid span12">
		<span class="span4">是否免费: ${dic:getLabelByValue(course.free, 'course_if_free')}</span>
		<span class="span4">学科: ${course.subject.name}</span>
		<span class="span4">主将老师: ${course.teacher.name}</span>
	</div>
	<div class="row-fluid span12">
		<img src="${course.cover}?x-oss-process=style/list">
	</div>
</div>
<tags:message content="${message}"/>
<div class="breadcrumb">
	<form id="form" action="${ctx}/business/eventcase/saveevent" method="post" class="hide">
		<input type="hidden" name="courseid" value="${course.id}"/>
		<input type="hidden" name="eventid"  id="eventid"/>
	</form>
	<input id="assignButton" class="btn btn-primary" type="button" value="添加作业"/>
	<script type="text/javascript">
        $("#assignButton").click(function(){
            top.$.jBox.open("iframe:${ctx}/business/event/select2?courseid=${course.id}&category="+3, "添加事件",810,$(top.document).height()-240,{
                buttons:{"确定添加":"ok", "清除已选":"clear", "关闭":true}, bottomText:"通过勾选时间后面的复选框进行添加事件。",submit:function(v, h, f){
                    var pre_ids = h.find("iframe")[0].contentWindow.pre_ids;
                    var ids = h.find("iframe")[0].contentWindow.ids;
                    if (v=="ok"){
                        var can=h.find("iframe")[0].contentWindow.can();
                        if (can=="")
                            top.$.jBox.tip("未给课程【${course.title}】分配新成员！", 'info');
                        else {
                            loading('正在提交，请稍等...');
                            //提交代码
                            $("#eventid").val(can);
                            $("#form").submit();
                            return true;
                        }
                        return false;
                    } else if (v=="clear"){
                        h.find("iframe")[0].contentWindow.clsCheckbox();
                        return false;
                    }
                }, loaded:function(h){
                    $(".jbox-content", top.document).css("overflow-y","hidden");
                }
            });
        });
	</script>
</div>
<form id="inputForm22" type="hidden">
	<input type="hidden" id="eventcaseid" name="eventcaseid">
	<input type="hidden" name="courseid" value="${course.id}">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr><th>事件名称</th><th>事件级别</th><th>是否在线</th><th>问题名称</th><th>问题描述</th><th>问题类型</th><th width="40px">作业地址</th><th>答案地址</th>
			<shiro:hasPermission name="business:course:addtask"><th>问题的修改或添加</th>
				<th>操作</th>
			</shiro:hasPermission></tr></thead>
		<tbody>
		<c:forEach items="${eventcaselist}" var="eventcase">
			<tr>
				<td>${eventcase.event.name}</td>
				<td>${dic:getLabelByValue(eventcase.event.level, 'event_level')}</td>
				<td>${dic:getLabelByValue(eventcase.event.online, 'event_online')}</td>
				<td>${eventcase.question.title}</td>
				<td>${eventcase.question.content}</td>
				<td>${dic:getLabelByValue(eventcase.question.type, 'question_type')}</td>
				<td>
					<c:if test="${eventcase.event.online eq 0}">
					<c:if test="${not empty eventcase.taskFileUrl}">
						<a href="javascript:;" onclick="downloadtest('${eventcase.taskFileUrl}')"
						   id="pluginurl"  style="color: #83AFE2;text-decoration:underline;" download style="display:none">下载</a>
					</c:if>
						<%--作业文件的上传 --%>
					<c:if test="${empty eventcase.taskFileUrl}">
						<input type="file" name="taskfiles" id="${eventcase.id}" onchange="uploadtaskfile2(${eventcase.id})" style="display: none"/>
						<input type="button" value="选择作业" onclick="xuanzezuoye(${eventcase.id})">
					</c:if>
					</c:if>
				</td>
				<td>
					<c:if test="${eventcase.event.online eq 0}">
					<c:if test="${not empty eventcase.answerFileUrl}">
						<a href="javascript:;" onclick="downloadtest2('${eventcase.answerFileUrl}')"
						   id="pluginurl3"  style="color: #83AFE2;text-decoration:underline;" download style="display:none">下载</a>
					</c:if>
						<%--答案文件的上传--%>

					<c:if test="${empty eventcase.answerFileUrl}">
						<input type="file" name="answerfiles" id="${eventcase.id}" onchange="uploadanswerfile2(${eventcase.id})" style="display: none"/>
						<input type="button" value="选择答案" onclick="xuanzedaan(${eventcase.id})">
					</c:if>
					</c:if>
				</td>
				<td>
					<c:if test="${eventcase.event.online eq 0}">
						<input id="assignButton3${eventcase.id}" class="btn btn-primary"  type="button" value="问题详情维护" disabled="disabled"/>
					</c:if>
					<c:if test="${eventcase.event.online eq 1}">
						<input id="assignButton3${eventcase.id}" class="btn btn-primary"  type="button" value="问题详情维护"/>
					</c:if>
					<script type="text/javascript">
						function xuanzezuoye(id) {
							$("#"+id).trigger("click");
                        }
                        function xuanzedaan(id) {
                            $("#"+id).trigger("click");
                        }
                        $("#assignButton3"+${eventcase.id}).click( function () {
                            top.$.jBox.open("iframe:${ctx}/business/question/form3?id=${eventcase.question.id}", "添加问题详情", 810, $(top.document).height() - 240, {
                                id:"iframe123",
                                buttons: {"确定添加": "ok","关闭": true},
                                bottomText: " 也可以通过移除按钮来删除已经添加的问题",
                                submit: function (v, h, f) {
                                    if (v == "ok") {
                                        h.find("iframe")[0].contentWindow.sub('${eventcase.id}','${course.id}');
                                        return true;
                                    } else if (v == "clear") {
                                        h.find("iframe")[0].contentWindow.clsCheckbox();
                                        return false;
                                    }
                                },
                                loaded: function (h) {
                                    $(".jbox-content", top.document).css("overflow-y", "hidden");
                                }
                            });
                        });
					</script>
				</td>
				<shiro:hasPermission name="business:course:addtask"><td>
					<a href="${ctx}/business/eventcase/removeeventcase?courseid=${course.id}&eventcaseid=${eventcase.id}"
					   onclick="return confirmx('确认要将事件实例从<b>[${eventcase.remarks}]</b>从<b>[${course.title}]</b>课程中移除吗？', this.href)">移除</a>
				</shiro:hasPermission>
				</td>
			</tr>

		</c:forEach>
		</tbody>
	</table>
</form>
</body>
</html>
